package com.central.scheduler.api.controller;

import com.central.common.annotation.LoginUser;
import com.central.common.annotation.RequiredPermission;
import com.central.common.constant.PermissionConstants;
import com.central.common.model.QueueInfo;
import com.central.common.model.Result;
import com.central.common.model.SysUser;
import com.central.scheduler.api.service.IScheduleService;
import com.central.scheduler.dao.model.Schedule;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author Tindy
 * @date 2022/2/23
 * @describe
 */
@RestController
@Api(tags = "定时器模块api")
@Slf4j
@RequestMapping("/schedule/")
public class SchedulerController {

    @Autowired
    private IScheduleService scheduleService;

    @ApiOperation(value = "新增或修改定时器")
    @PostMapping("/addOrUpdate")
    @RequiredPermission({PermissionConstants.DEV_USER, PermissionConstants.OPS_USER})
    public Result createOrUpdate(@ApiIgnore @LoginUser SysUser user, @RequestBody Schedule schedule){
        return scheduleService.createOrUpdate(user,schedule);
    }

    @ApiOperation(value = "定时器上下线")
    @GetMapping("/release")
    @RequiredPermission({PermissionConstants.DEV_USER, PermissionConstants.OPS_USER})
    public Result release(@ApiIgnore @LoginUser SysUser user, Long processDefinitionCode){
        return scheduleService.release(user,processDefinitionCode);
    }

    @ApiOperation(value = "定时器查询")
    @GetMapping("/querySchedule")
    public Schedule querySchedule(@ApiIgnore @LoginUser SysUser user, Long processDefinitionCode){
        return scheduleService.querySchedule(user,processDefinitionCode);
    }

}
